package com.njdf.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Enumeration;

public class PeopleFilter implements Filter {
    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        System.out.println("filter start...");
        HttpServletRequest request=(HttpServletRequest)req;
        Object people = request.getSession().getAttribute("people");
        if(people!=null) {
            chain.doFilter(req, resp);
            System.out.println("进来了哦");
        }else{
            System.out.println("拦截");
        }
    }

    @Override
    public void init(FilterConfig config) throws ServletException {
//        String filterName = config.getFilterName();
//        String paramName1 = config.getInitParameter("paramName1");
//        Enumeration initParameterNames = config.getInitParameterNames();
//        System.out.println(filterName);
//        System.out.println(paramName1);
//        while (initParameterNames.hasMoreElements()){
//            String name = (String) initParameterNames.nextElement();
//            String value = config.getInitParameter(name);
//            System.out.println(name+"="+value);
//        }
    }

}
